/*package main

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
)

var db *gorm.DB

func init() {
	dsn := "root:root123@tcp(127.0.0.1:3307)/student_schema?charset=utf8mb4&parseTime=True&loc=Local"
	var err error
	db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		log.Fatalf("failed to connect database: %v", err)
	}
}

type Student struct {
	ID    uint   `gorm:"primaryKey"`
	Name  string `gorm:"not null"`
	Age   int    `gorm:"not null"`
}

func createTable() {
	db.AutoMigrate(&Student{})
	log.Println("Table created or migrated.")
}

func insertData() {
	student := Student{Name: "周莹婕", Age: 20}
	db.Create(&student)
	log.Printf("Inserted student: %+v\n", student)
}

func modifyData() {
	var student Student
	db.First(&student, 1) 
	student.Age = 21
	db.Save(&student)
	log.Printf("Modified student: %+v\n", student)
}

func queryData() {
	var student Student
	db.First(&student, 1) 
	log.Printf("Queried student: %+v\n", student)
}

func deleteData() {
	var student Student
	db.Delete(&student, 1) 
	log.Println("Deleted student with ID 1.")
}

func main() {
	//createTable()  
	//insertData()  
    //modifyData()   
	//queryData()    
	deleteData()  
}